﻿using System;
using System.Collections.Generic;
using System.Text;
using SH;

namespace MTS
{
    internal class mtCSSServerCallback : mtOuterface<ImtCSSServerCallback>
    {
        public mtCSSServerCallback()
        {
            m_interfaceName = "mtCSSServerCallback";
            m_nClassID = ImtCSSServerCallback._classID;
        }
		
        protected override shErrorCode OnRequest(int nClassID, int nFuncID, string token, ref MTSSerializer sc) 
        {
            shErrorCode ec = shErrorCode.sh_ec_NoInterface;

            switch (nFuncID)
            {

                case ImtCSSServerCallback.CSSServerGetImageData:
                    {
                        mtImageRequest req = new mtImageRequest();

                        sc.serialize(req);

                        mtImageResponse rsp;

                        ec = m_pCallback.OnGetImageData(token, req, out rsp);
                        
                        if (ec == shErrorCode.sh_ec_Success)
                        {
                            sc = new MTSSerializer();

                            sc.serialize(rsp);
                        }
                    }
                    break;
                case ImtCSSServerCallback.CSSServerGetImageData2:
                    {
                        List<mtImageRequest> req = new List<mtImageRequest>();
                        List<mtImageResponse> rsp;
                        sc.serialize(req);

                        ec = m_pCallback.OnGetImageData(token, req,out rsp);
                       
                        if (ec == shErrorCode.sh_ec_Success)
                        {
                            sc = new MTSSerializer();

                            sc.serialize(rsp);
                        }
                    }
                    break;
                case ImtCSSServerCallback.CSSServerStorageCapacity:
                    {
                        mtStorageCapacityInfo info;

                        ec = m_pCallback.OnGetStorageCapacity(token,out info);

                        if (ec == shErrorCode.sh_ec_Success)
                        {
                            sc = new MTSSerializer();

                            sc.serialize(info);
                        }
                    }
                    break;
                case ImtCSSServerCallback.CSSServerDeleteImage:
                    {
                        mtDeleteImageDemand req = new mtDeleteImageDemand();
                        mtDeleteImageReply rsp;
                        sc.serialize(req);

                        ec = m_pCallback.OnDeleteImage(token, req, out rsp);

                        if (ec == shErrorCode.sh_ec_Success)
                        {
                            sc = new MTSSerializer();

                            sc.serialize(rsp);
                        }
                    }
                    break;
                case ImtCSSServerCallback.CSSServerSaveImage:
                    {
                        mtSaveImageRequest req = new mtSaveImageRequest();
                        mtSaveImageResponse rsp;
                        sc.serialize(req);

                        ec = m_pCallback.OnSaveImage(token, req,out rsp);

                        if (ec == shErrorCode.sh_ec_Success)
                        {
                            sc = new MTSSerializer();

                            sc.serialize(rsp);
                        }
                    }
                    break;
                case ImtCSSServerCallback.CSSServerRecognizeComplete:
                    {
                        mtRecognizeComplete info = new mtRecognizeComplete();

                        sc.serialize(info);

                        ec = m_pCallback.OnRecognizeComplete(token, info);
                    }
                    break;
                case ImtCSSServerCallback.CSSServerReconComplete:
                    {
                        mtReconComplete info = new mtReconComplete();

                        sc.serialize(info);

                        ec = m_pCallback.OnReconComplete(token, info);
                    }
                    break;
                default:
                    return ec;
            }

            return ec;
        }
        public override shErrorCode _OnInvokeOneWay(int nClassID, int nFuncID, string token, MTSSerializer sc)
        {
            var ec = OnRequest(nClassID, nFuncID, token, ref sc);

            if (ec != shErrorCode.sh_ec_NoInterface)
            {
                return shErrorCode.sh_ec_Success;
            }
            else
            {
                return shErrorCode.sh_ec_NoInterface;
            }
        }

        public override shErrorCode _OnInvokeTwoWay(int nClassID, int nFuncID, string token, ref MTSSerializer sc)
        {
            var ec = OnRequest(nClassID, nFuncID, token, ref sc);

            if (ec != shErrorCode.sh_ec_NoInterface)
            {
                sc.serialize(ref ec);
                return shErrorCode.sh_ec_Success;
            }
            else
            {
                return shErrorCode.sh_ec_NoInterface;
            }

        }
    }
}
